package EventManager;

import java.util.ArrayList;
import Driver.Facade;
import Model.Booking;

public class ViewBookingsForEventAdminRequest extends AdminRequest 
{

	private int eventId;
	private ArrayList<Booking> bookings = null;
	
	public ViewBookingsForEventAdminRequest(Administrator issuer, int eventId) 
	{
		super(issuer);		
		this.eventId = eventId;
	}

	public int getEventId() 
	{
		return eventId;
	}

	public void setEventId(int eventId) 
	{
		this.eventId = eventId;
	}
	
	/**
	 * Returns the bookings list
	 * @return List of bookings if the request was sustained, null otherwise
	 */
	public ArrayList<Booking> getBookings() 
	{
		return bookings;
	}

	public void setBookings(ArrayList<Booking> bookings) 
	{
		this.bookings = bookings;
	}

	@Override
	public String toString() 
	{
		return "ViewBookingsForEventRequest for event ID " + eventId;
	}
	
	@Override
	public void process(Administrator issuer)
	{
		try
		{
			super.process(issuer);
			ArrayList<Booking> allBookings = Facade.getManager().getBookings();
			ArrayList<Booking> bookingForSpecifiedEvent = new ArrayList<Booking>();
			for (Booking b : allBookings)
			{
				if (b.getEvent().getId() == getEventId())
				{
					bookingForSpecifiedEvent.add(b);
				}
			}
			setBookings(bookingForSpecifiedEvent);
			setStatus(RequestStatus.Sustained);
		}
		catch (Exception e)
		{
			setStatus(RequestStatus.Refused);
		}
	}
	
	

}
